package io.renren.modules.gengyun.controller;

import io.renren.common.Result;
import io.renren.modules.gengyun.feign.FileTestFeignService;
import io.renren.modules.gengyun.feign.TestUploadFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("gengyun/upload")
public class TestUploadController {
    @Autowired
    private  TestUploadFeignService testUploadFeignService;
    @Autowired
    private  FileTestFeignService fileTestFeignService;

    @RequestMapping(value="start", method = RequestMethod.POST)
    public String startSchedule(@RequestParam String canshu) {
        System.out.println();
        String str = testUploadFeignService.starttesT(canshu);
        System.out.println("gengyun ok:"+canshu+"++++");
        System.out.println(str);
       return str;
    }

    @RequestMapping(value="pause", method = RequestMethod.POST)
    public String startSchedule2(@RequestParam String password,@RequestParam String name) {
        System.out.println();
        String str = testUploadFeignService.starttesT2(password,name);
        System.out.println("gengyun ok:"+password+"++++"+name+":");
        System.out.println(str);
        return str;
    }

    @RequestMapping(value="resume", method = RequestMethod.POST)
    public Map<Object,Object> startSchedule3(@RequestParam Map<Object,Object> map) {
        System.out.println();
        Map<Object,Object> shuchu = testUploadFeignService.starttesT3(map);
        System.out.println("gengyun ok:"+map);
        System.out.println(shuchu);
        return shuchu;
    }

    @ResponseBody
    @RequestMapping(value = "/user_uploadFile",method = RequestMethod.POST)
    String create(@RequestParam("access_token") String accessToken, @RequestParam("file") MultipartFile file) {
        System.out.println("文件到服务端");
        System.out.println(accessToken);
        return "ok";
        //return fileTestFeignService.create(accessToken,file);
    }

    @RequestMapping("/BigFile")
    @ResponseBody
    public void upload(
            String name,
            String md5,
            Long size,
            Integer chunks,
            Integer chunk,
            MultipartFile file) throws IOException {
        System.out.println(name + " " + md5 + " " + file);
        System.out.println("ok 客户端");
        ResponseEntity<String> stringResponseEntity = fileTestFeignService.create(name, file);
    }

    @RequestMapping("/BigFile1")
    @ResponseBody
    public void upload1(
            String name,
            String md5,
            Long size,
            Integer chunks,
            Integer chunk,
            MultipartFile file) throws IOException {
        System.out.println(name + " " + md5 + " " + file);
        System.out.println("ok 客户端");
        fileTestFeignService.upload(name,md5,size,chunks,chunk,file);
    }


}
